#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main(void) {
    int k;
    scanf("%d", &k);
    for(int i = 0; i < k; i++) {
        int n, m;
        scanf("%d%d", &n, &m);
        int* items = (int*) calloc(n, sizeof(int));
        for (int x = 0; x < n; x++) {
            scanf("%d", &items[x]);
        }
        // 上冒泡排序
        for (int x = 0; x < n - 1; x++) {
            for (int y = 0; y < n - 1; y++) {
                if (items[y] > items[y + 1]) {
                    int tmp = items[y];
                    items[y] = items[y + 1];
                    items[y + 1] = tmp;
                }
            }
        }
        // 一个一个扫描过去
        int min = INT_MAX;
        int all = 0;
        for (int x = 0; x < n - m + 1; x++) {
            int price_diff = items[x + m - 1] - items[x];
            if (price_diff < min) {
                min = price_diff;
                all = 0;
                for (int y = 0; y < m; y++) {
                    all += items[x + y];
                }
            }
        }
        printf("%d %d\n", min, all);
        free(items);
    }
    return 0;
}
